from celery import Celery
from app.core.config import settings

# 创建Celery实例
celery_app = Celery("fuzznexus")

# 配置Celery
celery_app.conf.update(
    broker_url=settings.CELERY_BROKER_URL,
    result_backend=settings.CELERY_RESULT_BACKEND,
    task_serializer="json",
    accept_content=["json"],
    result_serializer="json",
    timezone="Asia/Shanghai",
    enable_utc=True,
    # 任务路由
    task_routes={
        "app.task_manager.tasks.*": {"queue": "fuzz_tasks"},
    },
    # 任务超时设置
    task_time_limit=settings.MAX_TASK_TIMEOUT,
    task_soft_time_limit=settings.MAX_TASK_TIMEOUT - 300,
    # 并发设置
    worker_concurrency=settings.MAX_WORKERS,
    # 结果过期时间（1天）
    result_expires=86400,
)

# 自动发现任务
celery_app.autodiscover_tasks(["app.task_manager"])